#include <sys/syscall.h>
#include <stdint.h>

extern void vt100_move_cursor(int x, int y);
extern void do_scheduler();

void sys_sleep(uint32_t time)
{
    // TODO:
    invoke_syscall(SYSCALL_SLEEP, time, IGNORE, IGNORE);
}

void sys_write(char *buff)
{
    // TODO:
    invoke_syscall(SYSCALL_WRITE, (uintptr_t)buff, IGNORE, IGNORE);
}

void sys_reflush()
{
    // TODO:
    invoke_syscall(SYSCALL_REFLUSH, IGNORE, IGNORE, IGNORE);
}

void sys_move_cursor(int x, int y)
{
    // TODO:
    invoke_syscall(SYSCALL_CURSOR, x, y, IGNORE);
}

long sys_get_timebase()
{
    // TODO:
    long time = invoke_syscall(SYSCALL_GET_TIMEBASE, IGNORE, IGNORE, IGNORE);
    return time;
}

long sys_get_tick()
{
    // TODO:
   long time = invoke_syscall(SYSCALL_GET_TICK, IGNORE, IGNORE, IGNORE);
   return time;
}

void sys_yield()
{
    // TODO:
    invoke_syscall(SYSCALL_YIELD, IGNORE, IGNORE, IGNORE);
    //   or
    // do_scheduler();
    // ???
}

uint32_t sys_get_wall_time(uint32_t *time_elapsed){
  uint32_t clock = invoke_syscall(SYSCALL_GET_WALL_TIME, time_elapsed, IGNORE, IGNORE);
  return clock;
}


/*--------------------------------------P3 ADD SYSCALL----------------------------------------------*/

int sys_get_char(){
    int c = (int)invoke_syscall(SYSCALL_GET_CHAR, IGNORE, IGNORE, IGNORE);
    return c;    
}

void sys_put_char(char ch){
    invoke_syscall(SYSCALL_PUT_CHAR, ch, IGNORE, IGNORE);
}

void sys_process_show(void){
    invoke_syscall(SYSCALL_PS, IGNORE, IGNORE, IGNORE);
}

void sys_screen_clear(void){
    invoke_syscall(SYSCALL_SCREEN_CLEAR, IGNORE, IGNORE, IGNORE);
}

void sys_exit(void){
    invoke_syscall(SYSCALL_EXIT, IGNORE, IGNORE, IGNORE);
}

int sys_kill(pid_t pid){
    int kill_status = (int)invoke_syscall(SYSCALL_KILL, pid, IGNORE, IGNORE);
    return kill_status;
}

pid_t sys_spawn(task_info_t *info, void* arg, spawn_mode_t mode){
    pid_t pid = (pid_t)invoke_syscall(SYSCALL_SPAWN, (uintptr_t)info, (uintptr_t)arg, mode);
    return pid;
}

int sys_waitpid(pid_t pid){
    int wait_status = (int)invoke_syscall(SYSCALL_WAITPID, pid, IGNORE, IGNORE);
    return wait_status;
}

pid_t sys_getpid(){
    pid_t pid1 = (pid_t)invoke_syscall(SYSCALL_GETPID, IGNORE, IGNORE, IGNORE);
    return pid1;
}

